package com.damieoa.damieoa.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.damieoa.damieoa.dao.StationMapper;
import com.damieoa.damieoa.pojo.Staff;
import com.damieoa.damieoa.pojo.Station;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StationServiceImpl implements StationService{

    @Autowired
    private StationMapper stationMapper;

    //增加岗位
    @Override
    public void addStation(Station station) {
        stationMapper.insert(station);
    }

    //查询岗位
    @Override
    public List<Station> queryStation(Station station) {
        if(station.getQuery_way().equals("station_id") ||
                station.getQuery_way().equals("station_name") ||
                station.getQuery_way().equals("station_type") ){
            QueryWrapper<Station> queryWrapper = new QueryWrapper<>();
            queryWrapper.like(station.getQuery_way(), station.getQuery_conditions());
            return stationMapper.selectList(queryWrapper);
        }else if (station.getQuery_way().equals("all")){
            QueryWrapper<Station> queryWrapper = new QueryWrapper<>();
            queryWrapper.like("station_id", station.getQuery_conditions())
                    .or().like("station_name", station.getQuery_conditions())
                    .or().like("station_type", station.getQuery_conditions());
            return stationMapper.selectList(queryWrapper);
        }else{
            return null;
        }
    }

    //删除岗位
    @Override
    public void deleteStation(Station station) {
        stationMapper.deleteStation(station);
    }

    //根据岗位id获取岗位信息
    @Override
    public Station getStationById(Station station) {
        return stationMapper.getStationById(station);
    }

    //修改岗位信息
    @Override
    public void updateStation(Station station) {
        stationMapper.updateStation(station);
    }

    //查询岗位员工
    @Override
    public List<Staff> queryStationStaff(Station station) {
        if (station.getStation_name().equals("全部查询")){
            station.setStation_name("");
            return stationMapper.queryStationStaff(station);
        }
        else {
            return stationMapper.queryStationStaff(station);
        }
    }

    //查询删除岗位员工
    @Override
    public void deleteStationStaff(Staff staff) {
         stationMapper.deleteStationStaff(staff);
    }

}
